package com.usian.controller;

import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.service.impl.WmUserServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
    private WmUserServiceImpl wmUserService;
    @PostMapping("save")
    @Override
    public ResponseResult save(@RequestBody WmUser wmUser) {
        if (wmUser==null) return wmUserService.paramError;
        wmUserService.save(wmUser);
       return ResponseResult.okResult(wmUser);
    }

    @Override
    @PostMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable String name) {
        return StringUtils.isNotEmpty(name)?wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name)):null;
    }

    @PostMapping("updateAuthorId")
    public ResponseResult updateAuthorId(@RequestBody WmUser wmUser){
        wmUserService.updateById(wmUser);
        return wmUserService.okResult;
    }
}
